package com.xilihui.xlh.business.requests;

import android.content.Context;

import com.xilihui.xlh.business.entities.AddressEntity;
import com.xilihui.xlh.business.entities.CommentEntity;
import com.xilihui.xlh.business.entities.ConfirmOrderEntity;
import com.xilihui.xlh.business.entities.HotKeyEntity;
import com.xilihui.xlh.business.entities.MyEvaluationEntity;
import com.xilihui.xlh.business.entities.NearbyStoreEntity;
import com.xilihui.xlh.business.entities.PayEntity;
import com.xilihui.xlh.business.entities.RecommendGoodEntity;
import com.xilihui.xlh.business.entities.RefundEntity;
import com.xilihui.xlh.business.entities.SearchGoodsEntity;
import com.xilihui.xlh.business.entities.SpecEntity;
import com.xilihui.xlh.business.entities.StoreCartListEntity;
import com.xilihui.xlh.business.entities.StoreClassEntity;
import com.xilihui.xlh.business.entities.StoreDetailsEntity;
import com.xilihui.xlh.business.entities.StoreGetPay;
import com.xilihui.xlh.business.entities.StoreGoodDetailsEntity;
import com.xilihui.xlh.business.entities.StoreHomeDataEntity;
import com.xilihui.xlh.business.entities.StoreMyOrderEntity;
import com.xilihui.xlh.constant.StrConst;
import com.xilihui.xlh.core.app.BaseEntity;
import com.xilihui.xlh.core.http.HttpManager;
import com.xilihui.xlh.core.util.SPUtil;
import com.xilihui.xlh.core.util.SignUtil;
import com.xilihui.xlh.core.util.TimeFormatUtil;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by Administrator on 2018/9/3.
 * 商城首页
 */

public class StoreRequest {

    public static StoreService service = HttpManager.getRetrofit().create(StoreService.class);

    /**
     * 洗理会 商城
     * @param page
     * @return
     */
    public static Observable<StoreHomeDataEntity> home(int page){
        
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("page",page+"");
        
        return service.home(temptime,app_key,page,SignUtil.sign(map));
    }

    /**
     * 商城首页 分类数据
     * @param page
     * @return
     */
    public static Observable<StoreClassEntity> goodClass(String cate_id,int page){
        
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("cate_id",cate_id);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("page",page+"");
        
        return service.goodClass(cate_id,temptime,app_key,page,SignUtil.sign(map));
    }

    /**
     * 商品详情
     * @param goods_id
     * @return
     */
    public static Observable<StoreDetailsEntity> details(Context context,String goods_id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("goods_id",goods_id);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("access_token",access_token);
        return service.details(access_token,goods_id,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 全部评价
     * @param goods_id
     * @param page
     * @return
     */
    public static Observable<CommentEntity> comment(String goods_id,int page){
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("goods_id",goods_id);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("page",page+"");
        return service.comment(goods_id,temptime,app_key,page,SignUtil.sign(map));
    }


    /**
     * 商城搜索
     * @param keyword
     * @param orderby
     * @param page
     * @return
     */
    public static Observable<SearchGoodsEntity> searchGoods(String keyword,String orderby,int page){
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("keyword",keyword);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("page",page+"");
        map.put("orderby",orderby);
        return service.searchGoods(keyword,orderby,temptime,app_key,page,SignUtil.sign(map));
    }

    /**
     * 商品 规格
     * @param key
     * @param goods_id
     * @return
     */
    public static Observable<SpecEntity> guige(String key,String goods_id){
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("key",key);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        map.put("goods_id",goods_id);
        return service.guige(key,goods_id,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 商城 加入购物车
     * @param context
     * @param goods_id
     * @param goods_num
     * @param item_id
     * @return
     */
    public static Observable<BaseEntity> addCart(Context context,String goods_id,String goods_num,String item_id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.addCart(access_token,goods_id,goods_num,item_id);
    }


    /**
     * 更新购物车
     * @param context
     * @return
     */
    public static Observable<BaseEntity> updateCart(Context context,String id,String item_id,String goods_num){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.updateCart(access_token,id,item_id,goods_num);
    }
    
    
    /**
     * 购物车 列表 
     * @param context
     * @return
     */
    public static Observable<StoreCartListEntity> cartList(Context context){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cartList(access_token);
    }

    /**
     * 收货地址 列表
     * @param context
     * @return
     */
    public static Observable<AddressEntity> address(Context context){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.address(access_token);
    }

    /**
     * 添加收货 地址
     * @param context
     * @param consigness
     * @param province
     * @param city
     * @param district
     * @param moblle
     * @param is_default
     * @param address
     * @return
     */
    public static Observable<BaseEntity> addAddress(Context context,String consigness,String province,
                                                    String city,String district,String moblle,String is_default,
                                                    String address){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.addAddress(access_token,consigness,province,city,district,moblle,is_default,address);
    }

    /**
     * 删除收货地址
     * @param context
     * @param address_id
     * @return
     */
    public static Observable<BaseEntity> deleteAddress(Context context,String address_id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.deleteAddress(access_token,address_id);
    }
    
    /**
     * 更新收货地址
     * @param context
     * @param address_id
     * @param consignee
     * @param province
     * @param city
     * @param disrict
     * @param moblie
     * @param is_default
     * @param address
     * @return
     */
    public static Observable<BaseEntity> updateAddress(Context context,String address_id,String consignee,String province,
                                                       String city,String disrict,String moblie,String is_default,String address){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.updateAddress(access_token,address_id,consignee,province,city,disrict,moblie,is_default,address);
    }

    /**
     * 推荐商品
     * @param page
     * @return
     */
    public static Observable<RecommendGoodEntity> recommendGood(int page){
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("page",page+"");
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        return service.recommendGoods(temptime,app_key,page+"",SignUtil.sign(map));
    }

    /**
     * 商品規格
     * @param context
     * @param id
     * @return
     */
    public static Observable<StoreDetailsEntity> goodsInfo(Context context,String id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.goodsInfo(id,access_token);
    }

    /**
     * 勾选单个商品
     * @param context
     * @param id
     * @param selected
     * @return
     */
    public static Observable<BaseEntity> selectOne(Context context,String id,String selected){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.select(access_token,id,selected);
    }

    /**
     * 全选商品
     * @param context
     * @param selected
     * @return
     */
    public static Observable<BaseEntity> selectAll(Context context,String selected){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.selectAll(access_token,selected);
    }

    /**
     * 确认订单
     * @param context
     * @return
     */
    public static Observable<ConfirmOrderEntity> confirmOrder(Context context){

        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        return service.confirmOrder(access_token,temptime,app_key,SignUtil.sign(map));
    }

    /**
     * 立即购买
     * @param context
     * @param goods_id
     * @param goods_num
     * @param item_id
     * @return
     */
    public static Observable<ConfirmOrderEntity> lijibuy(Context context,String goods_id,String goods_num,String item_id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.lijibuy(access_token,goods_id,goods_num,item_id);
    }

    /**
     * 删除购物车
     * @param context
     * @return
     */
    public static Observable<BaseEntity> deleteCart(Context context){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        String app_key = StrConst.app_key;
        String temptime = TimeFormatUtil.getTimestamp();

        HashMap<String,String> map = new HashMap<>();
        map.put("access_token",access_token);
        map.put("app_key",app_key);
        map.put("temptime",temptime);
        return service.deleteCart(access_token,temptime,app_key,SignUtil.sign(map));
    }


    /**
     * 添加订单
     * @param context
     * @param jsondata
     * @return
     */
    public static Observable<StoreGetPay> addOrder(Context context,String address_id,String type, String jsondata){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.addOrder(access_token,address_id,type,jsondata);
    }

    /**
     * 支付
     * @param context
     * @param order_all_sn
     * @param code
     * @return
     */
    public static Observable<PayEntity> pay(Context context,String order_all_sn,String code){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.pay(access_token,order_all_sn,code);
    }

    /**
     * 收藏商品
     * @param context
     * @param id
     * @param collect
     * @return
     */
    public static Observable<BaseEntity> collectCart(Context context,String id,String collect){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.collectCart(access_token,id,collect);
    }


    /**
     * 我的订单
     * @param context
     * @return
     */
    public static Observable<StoreMyOrderEntity> storeOrderf(Context context,String status,int page){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.storeOrderf(access_token,status,page);
    }

    /**
     * 取消订单
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> cancelOrder(Context context,String id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cancelOrder(access_token,id);
    }

    /**
     * 删除订单
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> deleteOrder(Context context,String id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.deleteOrder(access_token,id);
    }

    /**
     * 订单详情
     * @param context
     * @return
     */
    public static Observable<StoreGoodDetailsEntity> orderAllInfo(Context context,String order_id,String order_all_id){
        String access_token = (String) SPUtil.get(context,SPUtil.TOKEN,"");
        return service.orderAllInfo(access_token,order_id,order_all_id);
    }
    

    /**
     * 发布评论
     * @param id
     * @param content
     * @param zan_num
     * @return
     */
    public static Observable<BaseEntity> postEvaluation(Context context,String id,String content,String zan_num){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.comment(access_token,id,content,zan_num);
    }

    /**
     * 我的评价
     * @param context
     * @param page
     * @return
     */
    public static Observable<MyEvaluationEntity> evaluationList(Context context,int page){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.commentList(access_token,page);
    }

    /**
     * 确认收货
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> confirmReceipt(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.confirmReceipt(access_token,id);
    }

    /**
     * 附近门店
     * @param lat
     * @param lng
     * @param agent_id
     * @return
     */
    public static Observable<NearbyStoreEntity> nearbyStores(String lat,String lng,String agent_id,int page){
        return service.nearbyStores(lat,lng,agent_id,page);
    }
    
    /**
     * 热门搜索
     * @return
     */
    public static Observable<HotKeyEntity> keyWords(){
        return service.keywords();
    }


    /**
     * 退货 退款详情
     * @param context
     * @param order_id
     * @return
     */
    public static Observable<RefundEntity> returnGoods(Context context,String order_id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.returnGoods(access_token,order_id);
    };

    /**
     * 退款申请
     * @param context
     * @param order_id
     * @param reason
     * @return
     */
    public static Observable<BaseEntity> applyReturn(Context context,String order_id,String reason){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.applyRefund(access_token,order_id,reason);
    };

    
    /**
     * 撤销退款
     * @param context
     * @param id
     * @return
     */
    public static Observable<BaseEntity> cancelRefund(Context context,String id){
        String access_token = (String)SPUtil.get(context,SPUtil.TOKEN,"");
        return service.cancelReturn(access_token,id);
    }
    

}

